package com.qmx.qmxapp.fragment;


import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.Toast;

import com.qmx.qmxapp.R;
//import com.qmx.qmxapp.activity.CreateActivity;
import com.qmx.qmxapp.activity.AppointmentMeetingActivity;
import com.qmx.qmxapp.activity.CreateActivity;
import com.qmx.qmxapp.activity.HostMeetingActivity;
import com.qmx.qmxapp.activity.InitiateMeetingActivity;
import com.qmx.qmxapp.activity.JoinMeetingActivity;
import com.qmx.qmxapp.activity.MyScheduleActivity;
import com.qmx.qmxapp.activity.NewSetLiveActivity;
import com.qmx.qmxapp.activity.RoomActivity;
import com.qmx.qmxapp.adapter.BaseRecyclerAdapter;
import com.qmx.qmxapp.adapter.BaseRecyclerHolder;
import com.qmx.qmxapp.base.BaseActivity;
import com.qmx.qmxapp.base.BaseApplication;

import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @author ChengXiangtong
 * @create 2018/10/29
 * @Describe
 */
public class MeetingFragment extends Fragment {
    private List<String> list;
    private RecyclerView recyclerView;
    private BaseRecyclerAdapter<String> adapter;
    private View mView;

    @BindView(R.id.ll_join_meeting)
    LinearLayout ll_join_meeting;
    @BindView(R.id.ll_meeting_app)
    LinearLayout ll_meeting_app;
    @BindView(R.id.ll_host_meeting)
    LinearLayout ll_host_meeting;
    @BindView(R.id.ll_new_set_live)
    LinearLayout ll_new_set_live;
    @BindView(R.id.ll_me_schedule)
    LinearLayout ll_me_schedule;
    @BindView(R.id.ll_appointment_meeting)
    LinearLayout ll_appointment_meeting;


    public MeetingFragment() {
        // Required empty public constructor
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        mView = inflater.inflate(R.layout.fragment_meeting, container, false);
        ButterKnife.bind(this, mView);
        list = new ArrayList<>();

        initList();

        adapter = new BaseRecyclerAdapter<String>(getActivity(), list, R.layout.layout_meeting_item) {
            @Override
            public void convert(BaseRecyclerHolder holder, String item, int position, boolean isScrolling) {
                holder.setText(R.id.item_text_user_name, item.toString());
//                if (item.getImageUrl() != null){
//                    holder.setImageByUrl(R.id.item_image,item.getImageUrl());
//                }else {
//                    holder.setImageResource(R.id.item_image,item.getImageId());
//                }
            }

        };
        adapter.setOnItemClickListener(new BaseRecyclerAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(RecyclerView parent, final View view, int position) {
                Toast.makeText(getActivity(), String.format(Locale.CHINA, "你点击了第%d项,长按会删除！", position), Toast.LENGTH_SHORT).show();
            }
        });

        recyclerView = (RecyclerView) mView.findViewById(R.id.recyclerview);
        recyclerView.setLayoutManager(new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false));
        recyclerView.addItemDecoration(new DividerItemDecoration(getContext(), DividerItemDecoration.VERTICAL));
        recyclerView.setAdapter(adapter);

        return mView;

    }

    public void initList() {
        for (int i = 0; i < 55; i++) {
            list.add("测试" + i);
        }
    }


    @OnClick({R.id.ll_join_meeting, R.id.ll_appointment_meeting, R.id.ll_host_meeting, R.id.ll_me_schedule, R.id.ll_meeting_app, R.id.ll_new_set_live})
    public void onClick(View v) {
        Intent intent = new Intent();
        switch (v.getId()) {
            case R.id.ll_join_meeting:
                intent.setClass(getActivity(), JoinMeetingActivity.class);
                break;
            case R.id.ll_appointment_meeting:
                intent.setClass(getActivity(), AppointmentMeetingActivity.class);
                break;
            case R.id.ll_host_meeting:
                intent.setClass(getActivity(), HostMeetingActivity.class);
                break;
            case R.id.ll_me_schedule:
                intent.setClass(getActivity(), MyScheduleActivity.class);
                break;
            case R.id.ll_meeting_app:
                intent.setClass(getActivity(), InitiateMeetingActivity.class);
                break;
            case R.id.ll_new_set_live:
                intent.setClass(getActivity(), NewSetLiveActivity.class);
                break;
            default:
                return;
        }
        startActivity(intent);
    }

}
